package com.notepad.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class DBManager {
	
	private static volatile DBManager instance;
	private DBHelper dbHelper;
	private SQLiteDatabase writeableDatabase;
	private SQLiteDatabase readabledDatabase;
	
	public DBManager(Context context) {
		dbHelper = new DBHelper(context);
		writeableDatabase = dbHelper.getWritableDatabase();
		readabledDatabase = dbHelper.getReadableDatabase();
	}
	
	public SQLiteDatabase getWriteableDatabase() {
		return writeableDatabase;
	}
	
	public SQLiteDatabase getReadabledDatabase() {
		return readabledDatabase;
	}
	
	public void release(){
		writeableDatabase.close();
		readabledDatabase.close();
		writeableDatabase = null;
		readabledDatabase = null;
		dbHelper = null;
	}

	public static DBManager getInstance(Context context){
		if(instance == null){
			synchronized (DBManager.class) {
				if(instance == null){
					instance = new DBManager(context);
				}
			}
		}
		return instance;
		
	}
}
